package xin.nick.cloud.user.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Example;
import org.springframework.stereotype.Service;
import xin.nick.cloud.pojo.User;
import xin.nick.cloud.service.UserService;
import xin.nick.cloud.user.dao.UserDao;

import java.util.Objects;
import java.util.Optional;

/**
 * @author Nick
 * @date 2021/8/1
 * @description
 */
@Service
public class UserServiceImpl implements UserService {


    @Autowired
    private UserDao userDao;

    @Override
    public boolean register(String email, String password, String code) {
        return false;
    }

    @Override
    public boolean isRegistered(String email) {
        return false;
    }

    @Override
    public String login(String email, String password) {
        User user = new User();
        user.setEmail(email);
        user.setPassword(password);
        Example<User> example = Example.of(user);
        Optional<User> one = userDao.findOne(example);
        if (one.isEmpty() || Objects.isNull(one.get())) {
            return null;
        }
        user = one.get();
        return user.getEmail();
    }

    @Override
    public String info(String token) {
        return null;
    }
}
